package org.urbansoft.icl.record;

import java.util.ArrayList;
import org.apache.log4j.Logger;
import org.urbansoft.icl.field.Field;
import org.urbansoft.icl.field.GenericANField;
import org.urbansoft.icl.field.GenericANSField;
import org.urbansoft.icl.field.GenericBlankField;
import org.urbansoft.icl.field.GenericNBField;
import org.urbansoft.icl.field.GenericNField;
import org.urbansoft.icl.field.Position;
import org.urbansoft.icl.field.validation.RecordTypeValidator;

/**
 * 
 * @author Ricardo Reyes
 */
public class CheckDetailAddendumCRecord extends Record {
	public Field recordType;
	public Field checkDetailAddendumCRecordNumber;
	public Field endBankRoutingNumber;
	public Field bofdEndBusinessDate;
	public Field endBankItemSequenceNumber;
	public Field truncationIndicator;
	public Field endBankConvIndicator;
	public Field endBankCorrIndicator;
	public Field returnReason;
	public Field userField;
	public Field endBankIdentifier;
	public Field reserved;
	public Field userField2;

	private static Logger log = Logger
			.getLogger(CheckDetailAddendumARecord.class);

	/**
	 * Instantiates a new check detail addendum a record.
	 */
	public CheckDetailAddendumCRecord() {
		fields = new ArrayList<Field>();
		recordName = "Check Detail Addendum C Record";
		recordTypeNumber = "28";
		initFields();
	}

	/**
	 * Instantiates a new check detail addendum a record for read purpose.
	 */
	public CheckDetailAddendumCRecord(String read) {
		// log.info("New CheckDetailAddendumCRecord for READ");
		fields = new ArrayList<Field>();
		recordName = "Check Detail Addendum C Record";
		recordTypeNumber = "28";
		initFields2();
	}

	/**
	 * Inits the fields.
	 */
	private void initFields2() {
		try {

			/* cash header record */
			recordType = new GenericANField(new Position(1, 2), "Record Type");

			/* check detail addendum a record number */
			checkDetailAddendumCRecordNumber = new GenericANField(new Position(
					3, 4), "Check Detail Addendum C Record Number");

			/* bofd routing number */
			endBankRoutingNumber = new GenericANField(new Position(5, 13),
					"Endorsing Bank Routing Number");

			/* bofd business date */
			bofdEndBusinessDate = new GenericANField(new Position(14, 21),
					"BOFD Endorsement Business Date");

			/* bofd item sequence number */
			endBankItemSequenceNumber = new GenericANField(
					new Position(22, 36),
					"Endorsing Bank  Item Sequence Number");

			/* bofd deposit account number */
			truncationIndicator = new GenericANField(new Position(37, 37),
					"Truncation Indicator");

			/* bofd deposit branch */
			endBankConvIndicator = new GenericANField(new Position(38, 38),
					"Endorsing Bank Conversion Indicator");

			/* payee name */
			endBankCorrIndicator = new GenericANField(new Position(39, 39),
					"Endorsing Bank Correction Indicator");

			/* bofd conversion indicator */
			returnReason = new GenericANField(new Position(40, 40),
					"Return Reason");
			/* bofd correction indicator */
			userField = new GenericANField(new Position(41, 59), "User Field");

			/* user field */
			endBankIdentifier = new GenericANField(new Position(60, 60),
					"Endorsing Bank Identifier");

			/* reserved */
			reserved = new GenericANField(new Position(61, 80), "Reserved");

			userField2 = new GenericANField(new Position(81, 90), "User Field");

			fields.add(recordType);
			fields.add(checkDetailAddendumCRecordNumber);
			fields.add(endBankRoutingNumber);
			fields.add(bofdEndBusinessDate);
			fields.add(endBankItemSequenceNumber);
			fields.add(truncationIndicator);
			fields.add(endBankConvIndicator);
			fields.add(endBankCorrIndicator);
			fields.add(returnReason);
			fields.add(userField);
			fields.add(endBankIdentifier);
			fields.add(reserved);
			fields.add(userField2);

		} catch (Exception e) {
			log.fatal(e.getMessage(), e);
		}
	}

	/**
	 * Inits the fields.
	 */
	private void initFields() {
		try {

			/* cash header record */
			recordType = new GenericNField(new Position(1, 2),
					RecordTypeValidator.INSTANCE, "28", "Record Type");

			/* check detail addendum a record number */
			checkDetailAddendumCRecordNumber = new GenericNField(new Position(
					3, 4), "Check Detail Addendum C Record Number");
			checkDetailAddendumCRecordNumber.setFieldData("");

			/* bofd routing number */
			endBankRoutingNumber = new GenericNField(new Position(5, 13),
					"Endorsing Bank Routing Number");
			endBankRoutingNumber.setFieldData("");

			/* bofd business date */
			bofdEndBusinessDate = new GenericNField(new Position(14, 21),
					"BOFD Endorsement Business Date");
			bofdEndBusinessDate.setFieldData("");

			/* bofd item sequence number */
			endBankItemSequenceNumber = new GenericNBField(
					new Position(22, 36), "Endorsing Bank Item Sequence Number");
			endBankItemSequenceNumber.setFieldData("");

			/* bofd deposit account number */
			truncationIndicator = new GenericANSField(new Position(37, 37),
					"Trucation Indicator");
			truncationIndicator.setFieldData("");

			/* bofd deposit branch */
			endBankConvIndicator = new GenericANSField(new Position(38, 38),
					"Endorsing Bank Conversion Indicator");
			endBankConvIndicator.setFieldData("");

			/* payee name */
			endBankCorrIndicator = new GenericNField(new Position(39, 39),
					"Endorsing Bank Correction Indicator");
			endBankCorrIndicator.setFieldData("");

			/* bofd conversion indicator */
			returnReason = new GenericANField(new Position(40, 40),
					"Return Reason");
			returnReason.setFieldData("");

			/* bofd correction indicator */
			userField = new GenericBlankField(new Position(41, 59),
					"User Field");
			userField.setFieldData("");

			/* user field */
			endBankIdentifier = new GenericANSField(new Position(60, 60),
					"Endorsing Bank Identifier");
			endBankIdentifier.setFieldData("");

			/* reserved */
			reserved = new GenericBlankField(new Position(61, 80), "Reserved");
			reserved.setFieldData("");

			/* bofd correction indicator */
			userField2 = new GenericBlankField(new Position(81, 90),
					"User Field");
			userField2.setFieldData("");

			fields.add(recordType);
			fields.add(checkDetailAddendumCRecordNumber);
			fields.add(endBankRoutingNumber);
			fields.add(bofdEndBusinessDate);
			fields.add(endBankItemSequenceNumber);
			fields.add(truncationIndicator);
			fields.add(endBankConvIndicator);
			fields.add(endBankCorrIndicator);
			fields.add(returnReason);
			fields.add(userField);
			fields.add(endBankIdentifier);
			fields.add(reserved);
			fields.add(userField2);

		} catch (Exception e) {
			log.fatal(e.getMessage(), e);
		}
	}

}
